/*     */ package com.zimbra.cs.mailbox.calendar.tzfixup;
/*     */ 
/*     */ import com.zimbra.common.calendar.ICalTimeZone;
/*     */ import com.zimbra.common.calendar.WellKnownTimeZones;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.cs.service.mail.CalendarUtils;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class XmlFixupRules
/*     */ {
/*     */   private static void parseMatchers(Element matchElem, ICalTimeZone replacementTZ, List<TimeZoneFixupRules.Matcher> matchers)
/*     */     throws ServiceException
/*     */   {
/*  95 */     for (Iterator<Element> elemIter = matchElem.elementIterator(); elemIter.hasNext();) {
/*  96 */       Element elem = (Element)elemIter.next();
/*  97 */       String elemName = elem.getName();
/*  98 */       if (elemName.equals("any")) {
/*  99 */         matchers.add(new TimeZoneFixupRules.Matcher(replacementTZ));
/* 100 */       } else if (elemName.equals("tzid")) {
/* 101 */         String tzid = elem.getAttribute("id");
/* 102 */         matchers.add(new TimeZoneFixupRules.Matcher(tzid, replacementTZ));
/* 103 */       } else if (elemName.equals("nonDst")) {
/* 104 */         long offset = elem.getAttributeLong("offset");
/* 105 */         matchers.add(new TimeZoneFixupRules.Matcher(offset, replacementTZ));
/* 106 */       } else if (elemName.equals("rules")) {
/* 107 */         long stdOffset = elem.getAttributeLong("stdoff");
/* 108 */         long dstOffset = elem.getAttributeLong("dayoff");
/* 109 */         Element stdElem = elem.getElement("standard");
/* 110 */         int stdMon = (int)stdElem.getAttributeLong("mon");
/* 111 */         int stdWeek = (int)stdElem.getAttributeLong("week");
/* 112 */         int stdWkday = (int)stdElem.getAttributeLong("wkday");
/* 113 */         Element dstElem = elem.getElement("daylight");
/* 114 */         int dstMon = (int)dstElem.getAttributeLong("mon");
/* 115 */         int dstWeek = (int)dstElem.getAttributeLong("week");
/* 116 */         int dstWkday = (int)dstElem.getAttributeLong("wkday");
/* 117 */         TimeZoneFixupRules.Matcher m = new TimeZoneFixupRules.Matcher(stdOffset, stdMon, stdWeek, stdWkday, dstOffset, dstMon, dstWeek, dstWkday, replacementTZ);
/*     */         
/*     */ 
/* 120 */         matchers.add(m);
/* 121 */       } else if (elemName.equals("dates")) {
/* 122 */         long stdOffset = elem.getAttributeLong("stdoff");
/* 123 */         long dstOffset = elem.getAttributeLong("dayoff");
/* 124 */         Element stdElem = elem.getElement("standard");
/* 125 */         int stdMon = (int)stdElem.getAttributeLong("mon");
/* 126 */         int stdMday = (int)stdElem.getAttributeLong("mday");
/* 127 */         Element dstElem = elem.getElement("daylight");
/* 128 */         int dstMon = (int)dstElem.getAttributeLong("mon");
/* 129 */         int dstMday = (int)dstElem.getAttributeLong("mday");
/* 130 */         TimeZoneFixupRules.Matcher m = new TimeZoneFixupRules.Matcher(stdOffset, stdMon, stdMday, dstOffset, dstMon, dstMday, replacementTZ);
/*     */         
/*     */ 
/* 133 */         matchers.add(m);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private static void parseFixupRule(Element fixupRuleElem, List<TimeZoneFixupRules.Matcher> matchers) throws ServiceException
/*     */   {
/* 140 */     Element matchElem = fixupRuleElem.getElement("match");
/* 141 */     Element touchElem = fixupRuleElem.getOptionalElement("touch");
/* 142 */     Element replaceElem = fixupRuleElem.getOptionalElement("replace");
/* 143 */     if ((touchElem == null) && (replaceElem == null))
/* 144 */       throw ServiceException.FAILURE("Neither <touch> nor <replace> found in <fixupRule>", null);
/* 145 */     if ((touchElem != null) && (replaceElem != null))
/* 146 */       throw ServiceException.FAILURE("<fixupRule> must not have both <touch> and <replace>", null);
/*     */     ICalTimeZone replacementTZ;
/*     */     ICalTimeZone replacementTZ;
/* 149 */     if (touchElem != null) {
/* 150 */       replacementTZ = null;
/*     */     } else {
/* 152 */       Element wellKnownTzElem = replaceElem.getOptionalElement("wellKnownTz");
/* 153 */       if (wellKnownTzElem != null) {
/* 154 */         String tzid = wellKnownTzElem.getAttribute("id");
/* 155 */         ICalTimeZone replacementTZ = WellKnownTimeZones.getTimeZoneById(tzid);
/* 156 */         if (replacementTZ == null)
/* 157 */           throw ServiceException.FAILURE("Unknown TZID \"" + tzid + "\"", null);
/*     */       } else {
/* 159 */         Element tzElem = replaceElem.getOptionalElement("tz");
/* 160 */         if (tzElem == null)
/* 161 */           throw ServiceException.FAILURE("Neither <tz> nor <wellKnownTz> found in <replace>", null);
/* 162 */         replacementTZ = CalendarUtils.parseTzElement(tzElem);
/*     */       }
/*     */     }
/* 165 */     parseMatchers(matchElem, replacementTZ, matchers);
/*     */   }
/*     */   
/*     */   public static List<TimeZoneFixupRules.Matcher> parseTzFixup(Element tzFixupElem) throws ServiceException
/*     */   {
/* 170 */     List<TimeZoneFixupRules.Matcher> matchers = new ArrayList();
/* 171 */     for (Iterator<Element> elemIter = tzFixupElem.elementIterator("fixupRule"); elemIter.hasNext();) {
/* 172 */       Element fixupRuleElem = (Element)elemIter.next();
/* 173 */       parseFixupRule(fixupRuleElem, matchers);
/*     */     }
/* 175 */     return matchers;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/mailbox/calendar/tzfixup/XmlFixupRules.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */